import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/main/main_controller.dart';
import 'package:yysk_app/routes/global_controller.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/button_widget.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/input_widget.dart';
import 'package:oktoast/oktoast.dart';

//绑定邀请码
Future<void> showInvitedSheet() async {
  final GlobalController globalController = Get.find();
  final MainController controller = Get.find();
  controller.invitedController.clear();
  controller.invitedCode.value = '';
  showDialog(
    context: Get.context!,
    builder: (BuildContext context) {
      return Dialog(
        backgroundColor: AppColors.backgroundColorBlackLight,
        child: Padding(
          padding: EdgeInsets.fromLTRB(22.px, 22.px, 22.px, 16.px),
          child: Stack(
            clipBehavior: Clip.none,
            children: [
              Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    '绑定邀请人',
                    style: TextStyle(
                      color: AppColors.fontColor,
                      fontSize: 15.px,
                    ),
                  ),
                  hiSpace(height: 10.px),
                  Text(
                    '官方邀请码：${globalController.staticInfo.value?.officalInviteCode ?? 888888}',
                    style: TextStyle(
                      color: AppColors.fontColorGray99,
                      fontSize: 13.px,
                    ),
                  ),
                  hiSpace(height: 13.px),
                  InputWidget(
                    maxLength: 6,
                    controller: controller.invitedController,
                    inputType: TextInputType.text,
                    hint: '请输入推荐人邀请码',
                    onChanged: (value) {
                      controller.invitedCode.value = value;
                    },
                    backgroundColor: AppColors.backgroundColorGreyF8,
                    buttonRadio: 300,
                  ),
                  hiSpace(height: 21.px),
                  ButtonWidget(
                    label: '确认绑定',
                    height: 36.px,
                    width: 264.px,
                    fontSize: 15.px,
                    fontColor: AppColors.fontColor21,
                    colorStart: AppColors.fontColorStart00,
                    colorEnd: AppColors.fontColorEnd00,
                    onPressed: () {
                      if (controller.invitedCode.value == '') {
                        showToast('请输入邀请码');
                        return;
                      }
                      globalController
                          .updateInvited({
                            'inviteCode': controller.invitedCode.value,
                          })
                          .then(
                            (res) => {
                              if (res.code == 200)
                                {Navigator.of(context).pop()},
                            },
                          );
                    },
                  ),
                  hiSpace(height: 8.px),
                ],
              ),
              Positioned(
                right: 0.px,
                top: 0.px,
                child: GestureDetector(
                  onTap: () {
                    Navigator.of(context).pop();
                  },
                  child: ImageAssetWidget(
                    imageUrl: 'static/images/close_dialog.png',
                    height: 20.px,
                    width: 20.px,
                  ),
                ),
              ),
            ],
          ),
        ),
      );
    },
  );
}
